package com.angel.controller;

import com.angel.bean.UserInfo;
import com.angel.service.UserInfoService;
import com.angel.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 修改用户信息
 */
@Controller
@RequestMapping("/mo")
public class UserModifyInfo {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * 反回用户信息修改页面
     * @return
     */
    @RequestMapping("/modifyInfo")
    public String userInfo(Model model){
        model.addAttribute(UserUtils.getPrincipal().getUserInfo());
        return "modify_info";
    }
    @RequestMapping("/update")
    @ResponseBody
    public Object updateUserInfo(UserInfo userInfo){
        Map<String,Object> map=new HashMap<>();
        map.put("emp",false);
            System.out.println("进了");
            userInfo.setId(UserUtils.getPrincipal().getUserInfo().getId());
            int result=userInfoService.update(userInfo);
            if (result!=0){
                map.put("emp",true);
            }else {
                map.put("emp",false);
            }
        return map;
    }
}
